﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Acms.Bll;
using Acms.AcmsControls;
using Telerik.Web.UI;

namespace PureStretch.Web
{
    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected AcmsContext AcmsContext
        {
            get
            {
                if (Page is TemplatePage)
                {
                    return ((TemplatePage)Page).AcmsContext;
                }
                return null;
            }
        }

        protected void menu_ItemDataBound(object sender, Telerik.Web.UI.RadMenuEventArgs e)
        {
            Post post = e.Item.DataItem as Post;
            if (post != null)
            {
                if (AcmsContext != null && AcmsContext.CurrentPost != null && AcmsContext.CurrentPost.Path.StartsWith(post.Path))
                {
                    e.Item.HighlightPath();
                }
            }
        }

        private Acms.Bll.Menu _MainMenu;
        private Acms.Bll.Menu MainMenu
        {
            get
            {
                if (_MainMenu == null)
                {
                    _MainMenu = Acms.Bll.Menu.GetByNameAndSiteId("Main", AcmsContext.SiteId);
                    if (_MainMenu == null)
                    {
                        throw new Exception("Cannot load menu 'Main'");
                    }
                }
                return _MainMenu;
            }
        }

    }
}
